package com.feihao.demo01DateJDK8;

import javafx.scene.input.DataFormat;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public class DemoChronoUtinTest {
    public static void main(String[] args) {
        String birthday = "1996-06-15";
        String death = "2096-08-08";


        //获取格式化形式：
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        //将字符串日期解析为LocalDate对象：
        LocalDate bir = LocalDate.parse(birthday, dtf);
        LocalDate dea = LocalDate.parse(death, dtf);

        //使用工具类：
        long between = ChronoUnit.YEARS.between(bir, dea);
        System.out.println(between);
    }
}
